package cn.springboot.admin;

import cn.springboot.model.Item;
import cn.springboot.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * index
 *
 * @author junrui.wang
 * @create 2017/6/7
 */
@Controller
@ResponseBody
public class IndexController {

    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index(){
        return "index";
    }

    @RequestMapping(value = "/user1/{id}", method = RequestMethod.GET)
    public ModelAndView getUser(@PathVariable("id") String id){
        User user = new User();
        user.setId(id);
        user.setName("admin");
        user.setPassword("admin");
        ModelMap model = new ModelMap();
        model.addAttribute("user", user);
        return new ModelAndView("user", model);
    }

    @RequestMapping(value = "/user/user/user", method = RequestMethod.GET)
    public User getUser(){
        User user = new User();
        user.setId("002");
        user.setName("admin");
        user.setPassword("admin");
        return user;
    }

    @RequestMapping(value = "/item", method = RequestMethod.GET)
    public Item getItem(){
        Item item = new Item();
        item.setId("item");
        return item;
    }

}
